home *** CD-ROM | disk | FTP | other *** search
- /**************************************************
- *
- * Moov stuff
- *
- *
- ***************************************************/
-
- #include "Movies.h"
- #include "Mini Player.h"
-
-
- /**************************************************
- *
- * Globals
- *
- ***************************************************/
-
- /* Info about the movie */
- Movie theMovie;
- Rect dispBounds;
-
- OSErr theErr; /* Saves having to declare it everywhere */
-
- /* Stuff for cursor control */
- ControlHandle movieScrollControlH;
- Boolean trackingHand;
- Point trackStart;
- Fixed playSpeed;
-
- extern WindowPtr moovWindow; /* Window picture is displayed in */
- extern Cursor playCursor, reverseCursor, pauseCursor, blinkCursor;
-
-
- /**************************************************
- *
- * SetUpMovies() Initializes the movie tools
- *
- ***************************************************/
- void SetUpMovies()
-
- {
- theErr = EnterMovies(); /* This would normally with the other manager inits */
- if (theErr) DebugStr((StringPtr)"\pEnterMovies Failed");
-
- theMovie = 0; /* Set theMovie to 0 to mark it as unused */
-
- }
-
-
-
- /**************************************************
- *
- * OpenTheMovie(fn,vRef)
- * Opens the movie named fn and starts it up
- * on exit:
- * moovWindow = resized and titled window
- * m = movie
- *
- ***************************************************/
- void OpenTheMovie(fn,vRef)
- Str255 fn;
- int vRef;
- {
- short movieResRefNum;
- FSSpec mySpec; /* File System record for the file */
-
-
- /* Make an FSSpec record of the info */
- theErr = FSMakeFSSpec(vRef,0,fn,&mySpec);
-
- /* First open the movie file */
- if (theErr = OpenMovieFile(&mySpec, &movieResRefNum, 0))
- return; /* Bail out if it didn't work */
-
- if (theErr = NewMovieFromFile( &theMovie,movieResRefNum, nil, nil,0, nil ))
- return; /* Bail out if it didn't work */
-
- CloseMovieFile(movieResRefNum); /* We're done with the resource fork */
-
- if (theErr = GetMoviesError()) /* Bail out if it didn't work */
- return;
-
- /* Get the bounds for the movie and make sure the top left is 0,0 */
- /* so the movie won't be offset within the window */
- GetMovieBox( theMovie, &dispBounds);
- OffsetRect(&dispBounds,-dispBounds.left,-dispBounds.top);
- SetMovieBox(theMovie, &dispBounds);
-
- if (theErr = GetMoviesError()) /* Bail out if it didn't work */
- return;
-
-
- /* Set up the window for the movie to play in */
- SizeWindow(moovWindow,dispBounds.right,dispBounds.bottom + 16,false);
- SetWTitle(moovWindow,fn); /* Set the title. You could use the movie name */
- ShowWindow(moovWindow); /* Make it visible */
- SelectWindow(moovWindow); /* and in front */
-
- /* Put a scroll control along the bottom */
- MakeMovieControls();
-
- SetMovieGWorld(theMovie,nil,nil); /* Play the movie in the window */
- GotoBeginningOfMovie(theMovie);
- PrerollMovie(theMovie,0,0); /* Get the movie ready to play */
- SetMovieActive(theMovie,true);
- StartMovie(theMovie); /* Start the movie */
-
-
- /* Initialize stuff for cursor control */
- trackingHand = false;
- playSpeed = x1Speed;
-
- }
-
- /**************************************************
- *
- * MakeMovieControls() Puts the controls at the bottom of the window
- *
- ***************************************************/
- void MakeMovieControls()
-
- {
- Rect hScrollRect;
- int min, max, curVal;
-
- min = 0;
- max = GetMovieDuration(theMovie); /* What if the movie is over 4 min? */
- curVal = 0;
-
- hScrollRect = moovWindow->portRect; /* Size the scroll bar */
- hScrollRect.bottom += 1;
- hScrollRect.right += 1;
- hScrollRect.left -= 1 ;
- hScrollRect.top = hScrollRect.bottom - 17;
-
- movieScrollControlH = NewControl(moovWindow,&hScrollRect,(StringPtr)"\p",true,
- curVal,min,max,scrollBarProc,0L);
-
- }
-
- /**************************************************
- *
- * MyMoviesTask() Calls MoviesTask and stops at the end
- * This is called from the main event loop of the application
- *
- ***************************************************/
- void MyMoviesTask()
-
- {
- if (theMovie)
- {
- SetCtlValue(movieScrollControlH,GetMovieTime(theMovie,nil)); /* Update thumb to current time */
-
- MoviesTask(theMovie,0);
- if (IsMovieDone(theMovie)) /* Has movie reached the end */
- {
- StopMovie(theMovie); /* Make sure it stopped */
- playSpeed = 0; /* Switch to the Pause cursor */
- }
- }
- }
-
-
- /**************************************************
- *
- * CleanUpMovie() Throws out the movie
- *
- ***************************************************/
- void CleanUpMovie()
-
- {
- if(theMovie)
- {
- DisposeMovie(theMovie);
- DisposeControl(movieScrollControlH);
- theMovie = 0;
- }
- }
-
-
- /**************************************************
- *
- * MovieScrollProc(theControl, theCode)
- * Procedure called from TrackControl when tracking the scroll bar
- * The buttons move the movie by 1 movie time unit
- * The page up/down move the movie by a second
-
- *
- ***************************************************/
- pascal void MovieScrollProc(ControlHandle theControl, int theCode)
- {
- int curControlValue,minControlValue,maxControlValue,theDelta;
-
- curControlValue = GetCtlValue(theControl); /* Get scroll value & limits */
- minControlValue = GetCtlMin(theControl);
- maxControlValue = GetCtlMax(theControl);
-
- switch (theCode)
- {
- case inPageDown:
- theDelta = GetMovieTimeScale(theMovie); /* The timescale is 1 secs worth */
- break;
-
- case inDownButton:
- theDelta = +1;
- break;
-
- case inPageUp:
- theDelta = -GetMovieTimeScale(theMovie);
- break;
-
- case inUpButton:
- theDelta = -1;
- break;
- }
-
- curControlValue += theDelta; /* Get the new value */
- if (curControlValue < minControlValue) /* Make sure it is in range */
- curControlValue = minControlValue;
- else if (curControlValue > maxControlValue)
- curControlValue = maxControlValue;
-
- SetMovieTimeValue(theMovie,curControlValue); /* Position the movie to the new time */
- MyMoviesTask(); /* Call our movies task routine
- to update the control and the movie */
-
- }
-
- /**************************************************
- *
- * MovieMouseDown(theWindow, thePoint)
- * Mouse pressed in movie content
- *
- ***************************************************/
- void MovieMouseDown(theWindow, thePoint)
-
- WindowPtr theWindow;
- Point thePoint;
-
- {
- ControlHandle theControl;
- short thePart;
-
- if( theWindow == moovWindow)
- {
- GlobalToLocal(&thePoint); /* Convert to window's local coords */
- thePart = FindControl(thePoint,theWindow,&theControl); /* In a control? */
-
- if (!thePart)
- {
- /* In the content area */
- trackingHand = true; /* Flag we are tracking the movie */
- trackStart = thePoint; /* Save where it was pressed */
- }
- else
- {
- /* In the scroll control */
- if (thePart == inThumb)
- {
-
- thePart = TrackControl(theControl,thePoint,nil);
- SetMovieTimeValue(theMovie,GetCtlValue(movieScrollControlH));
- }
- else
- thePart = TrackControl(theControl,thePoint,(ProcPtr) &MovieScrollProc);
-
- }
- }
- }
-
- /**************************************************
- *
- * MovieMouseUp(theWindow, thePoint)
- * Mouse released in movie content
- * If mouse moved right > 8, add one to playing speed.
- * If mouse moved left > 8, subtract one from playing speed
- * If mouse moved <= 8 stop
- *
- ***************************************************/
- void MovieMouseUp(theWindow, thePoint)
-
- WindowPtr theWindow;
- Point thePoint;
-
- {
- int amountMoved;
-
- if( trackingHand && (theWindow == moovWindow))
- {
- /* Figure out new playing speed */
- GlobalToLocal(&thePoint); /* Convert to window's local coords */
- amountMoved = thePoint.h - trackStart.h;
-
- if (amountMoved < -8) /* Moved left? */
- { /* If so, make speed more negative */
- playSpeed -=x1Speed; /* It's a fixed point number!!!!! */
- if (playSpeed == 0) /* Skip over 0 */
- playSpeed = -x1Speed;
- }
- else if (amountMoved > 8) /* Moved right? */
- {
- playSpeed +=x1Speed;
- if (playSpeed == 0) /* Skip over 0 */
- playSpeed = x1Speed;
- }
- else /* Didn't move so pause */
- playSpeed = 0;
-
- SetMovieRate(theMovie,playSpeed ); /* Set the new rate befire calling IsMovieDone */
-
- /* If playing forward and at end, go back to the start */
- if( (playSpeed > 0) && (theErr = IsMovieDone(theMovie)) )
- GotoBeginningOfMovie(theMovie);
-
- /* Or if playing backwards and at start, go back to the end */
- else if( (playSpeed < 0) && (theErr = IsMovieDone(theMovie)) )
- GotoEndOfMovie(theMovie);
-
- }
- }
-
-
- /**************************************************
- *
- * MovieCursor()
- *
- * Sets to proper movie cursor
- * uses a different cursor for pause, forward, and reverse play
- *
- ***************************************************/
- void MovieCursor()
- {
-
- static long nextTime = 0;
- static Boolean inBlink = false;
- long curTime;
-
- /* Blink the cursor every 20 ticks */
- if ( (curTime = TickCount()) >= nextTime)
- {
- nextTime = curTime+20;
- inBlink = !inBlink;
- }
- if (inBlink)
- SetCursor(&blinkCursor);
- else if (playSpeed > 0)
- SetCursor(&playCursor);
- else if (playSpeed < 0)
- SetCursor(&reverseCursor);
- else
- SetCursor(&pauseCursor);
-
- }
-
- /**************************************************
- *
- * DoMovieUpdate()
- *
- * Updates the movie screen
- *
- ***************************************************/
- void DoMovieUpdate()
- {
- if (theMovie)
- UpdateMovie(theMovie);
- }
-